{{template "header.html" .}}
<div id="link-list-container" class="container">
    <div id="link-list-header" class="clear">
        <h2 class="h2 left">友情链接</h2>
        <button class="right btn save" id="link-list-add">添加链接</button>
    </div>
    <table id="link-list-table" class="table">
        <thead>
        <tr>
            <th>ID</th>
            <th>名称</th>
            <th>URL</th>
            <th>简介</th>
            <th class="opt"></th>
        </tr>
        </thead>
        <tbody>{{range .Links}}
        <tr id="link-{{.id}}">
            <td class="link-id">{{.id}}{{if eq .status "pending"}}<a class="link-pending" href="/admin/links/approve/{{.id}}/">审核</a>{{end}}</td>
            <td>{{.title}}</td>
            <td><a href="{{.url}}" class="link-url" target="_blank">{{.url}}</a></td>
            <td>{{.desc}}</td>
            <td class="opt">
                <a class="link-edit" href="/admin/links/edit/{{.id}}/" rel="{{.id}}">修改</a>
                <a class="link-delete" href="/admin/links/delete/{{.id}}/" rel="{{.id}}">删除</a>
            </td>
        </tr>{{end}}
        </tbody>
    </table>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        $("#link-list-add").on("click", function () {
            window.location.href = "/admin/links/add";
        });
        $('.link-delete').on("click", function () {
            if (!confirm("确认删除？")) {
                return false;
            }
            var id = $(this).attr("rel");
            var url = $(this).attr("href");
            ajaxRequest(null, url, "delete", {}, function (json) {
                if (json.res) {
                    $('#link-' + id).remove();
                }
            });
            return false;
        });
    });
</script>
</body>
</html>